import 'package:fstudy/src/database/migration/versions.dart';
import 'package:sqflite/sqflite.dart';
import 'package:uuid/v4.dart';

import '../../data/models/setting.dart';

class V1 implements AbsMigration {
  @override
  void migrate(Database db) {
    db.execute(
      'CREATE TABLE dify_conversations(id TEXT PRIMARY KEY, conversation_id TEXT, mode TEXT, query TEXT, answer TEXT, files TEXT, metadata TEXT, created_at INTEGER)',
    );
    db.execute('CREATE TABLE settings(name TEXT PRIMARY KEY, val TEXT)');
    final uuid = UuidV4();
    final s = Setting(name: Setting.sDeviceId, val: uuid.generate());
    db.insert(
      'settings',
      s.toMap(),
      conflictAlgorithm: ConflictAlgorithm.replace,
    );
  }

  @override
  void rollback(Database db) {
    db.execute('DROP TABLE dify_conversations');
    db.execute('DROP TABLE settings');
  }
}
